<template>
    <div class="body">
    <img
      src="../../assets/img/hong/one/header.png"
      alt=""
      class="texter"
    >
    <div class="add">
      <img
        src="../../assets/img/hong/one/title2.png"
        alt=""
        class="imag"
      >
      <ul>
        <li
          v-for="item in list"
          :key="item.goods_id"
          @click="nav(item)"
        >
          <img
            class="img"
            v-lazy="item.goods_img"
            :key="item.goods_img"
          >
          <div class="text">
            {{item.goods_name}}
          </div>
          <div class="money">
            ¥
            <span>{{item.active_price}}</span>
          </div>
          <img
            src="../../assets/img/hong/one/qiang.png"
            class="shopping"
            alt=""
          >
        </li>
      </ul>
    </div>
    <div class="add">
      <img
        src="../../assets/img/hong/one/title1.png"
        alt=""
        class="imag"
      >
      <ul>
        <li
          v-for="item in listdev"
          :key="item.goods_id"
          @click="nav(item)"
        >
          <img
            class="img"
            v-lazy="item.goods_img"
            :key="item.goods_img"
          >
          <div class="text">
            {{item.goods_name}}
          </div>
          <div class="money">
            ¥
            <span>{{item.active_price}}</span>
          </div>
          <img
            src="../../assets/img/hong/one/gou.png"
            class="shopping"
            alt=""
          >
        </li>
      </ul>
    </div>

    <!-- 置顶 -->
    <div
      class="totop"
      id="totop"
      @click="backTop"
      v-show="btnFlag"
    >
    </div>
  </div>
</template>

<script>
import bridge from '../../js/js1'
import { index, Coupondev } from '@/api/index'
import { share } from '../../js/public'
import { getSystem, openApp, getUrlQuery, parseKeyValue } from '../../js/js'
export default {
  // 组件名称
  name: '',
  // 局部注册的组件
  components: {},
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
    return {
      list: [],
      listdev: [],
      system: getSystem(),
      btnFlag: false,
    }
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  destroyed () {
    window.removeEventListener('scroll', this.scrollToTop);
  },
  // 生命周期钩子   注：没用到的钩子请自行删除
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  created () {
    this.create()
  },
  /**
  * el 被新创建的 vm.el 替换，并挂载到实例上去之后调用该钩子。
  * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.el 也在文档内。
  */
  mounted () {
    window.addEventListener('scroll', this.scrollToTop)
  },
  // 组件方法
  methods: {
    async create () {
      try {
        const res = await index({
          id: 96
        })
        console.log(res.data.data.types);
        this.list = res.data.data.types[0].goods.slice(0, 6)
        this.listdev = res.data.data.types[0].goods.slice(6, 99)
      } catch (err) {
        console.log('错误');
      }
    },
    // 点击图片回到顶部方法，加计时器是为了过渡顺滑
    backTop () {
      const that = this
      let timer = setInterval(() => {
        let ispeed = Math.floor(-that.scrollTop / 5)
        document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed
        if (that.scrollTop === 0) {
          clearInterval(timer)
        }
      }, 16)
    },
    // 为了计算距离顶部的高度，当高度大于60显示回顶部图标，小于60则隐藏
    scrollToTop () {
      const that = this
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      that.scrollTop = scrollTop
      // console.log(that.scrollTop);
      if (that.scrollTop > 800) {
        that.btnFlag = true
      } else {
        that.btnFlag = false
      }
    },
    // 跳转下载
    nav (item) {
      console.log(item.goods_id);
      // window.locaition.href = 'http://yuanfuda933.oss-cn-zhangjiakou.aliyuncs.com/yfdMall_1_v1.0.1.apk?squId=' + 'item.goods._id'
      window.location.href = 'yfd://yfdmall:8080/goodsDetail?spuId=' + item.goods_id
    },
    href (uri, blank = true) {
      const a = document.createElement('a')
      a.style.display = 'none'
      a.href = uri
      if (blank) a.setAttribute('target', '_blank')
      document.body.appendChild(a)
      a.click()
      setTimeout(t => {
        document.body.removeChild(a)
      }, 0)
    },
  }
}
</script>

<style scoped lang="less">
.body {
  overflow: hidden;
  min-width: 320px;
  max-width: 750px;
  width: 10rem;
  background: #da3893;
  margin: 0 auto;
  line-height: 1.5;
  font-family: Arial, Helvetica;
  .totop {
    position: fixed;
    width: 1.2rem; /* 40/16 */
    height: 1.2rem;
    border-radius: 1.25rem /* 20/16 */;
    opacity: 0.8;
    background: url("../../assets/ding.png") no-repeat;
    background-size: contain;
    box-shadow: 0 1px 5px 0 #e0e0e0;
    right: 0.125rem; /* 18/16 */
    bottom: 3rem; /* 64/16 */
    z-index: 1100;
    -webkit-transition: opacity 0.5s;
    transition: opacity 0.5s;
  }
  .add:nth-child(2) {
    background: #ab34e6;
  }
  .add:nth-child(2) .shopping {
    width: 1.2rem;
    height: 1.2rem;
    bottom: 0%;
    animation: mymove 2s infinite;
    -webkit-animation: mymove 2s infinite; /*Safari and Chrome*/
    animation-direction: alternate; /*轮流反向播放动画。*/
    animation-timing-function: ease-in-out; /*动画的速度曲线*/
    /* Safari 和 Chrome */
    -webkit-animation: mymove 2s infinite;
    -webkit-animation-direction: alternate; /*轮流反向播放动画。*/
  }
  .add:nth-child(3) {
    background: #ff3db6;
  }
  .add {
    width: 9.653333rem;
    margin: 0.133333rem auto 0.533333rem;
    border-radius: 0.4rem;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    padding-top: 1.6rem;
    .imag {
      position: absolute;
      top: 0%;
      width: 100%;
      height: 3.573333rem;
    }
    ul {
      li {
        z-index: 99;
        float: left;
        width: 4.56rem;
        height: 6.64rem;
        border-radius: 0.166667rem;
        background: #ffffff;
        margin-bottom: 0.266667rem;
        margin-left: 0.186667rem;
        position: relative;
        .shopping {
          position: absolute;
          right: 6%;
          bottom: 4%;
          width: 0.746667rem;
          height: 0.746667rem;
        }
        .img {
          width: 3.493333rem;
          height: 3.173333rem;
          margin-top: 0.773333rem;
          margin-left: 0.506667rem;
        }
        .text {
          margin: 0.206667rem auto 0;
          width: 3.093333rem;
          height: 1.033333rem;
          font-weight: 600;
          font-size: 0.373333rem;
          color: #333333;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .money {
          margin-left: 0.646667rem;
          // width: 1.333333rem;
          // height: 0.426667rem;
          font-size: 0.373333rem;
          color: #ff301e;
          span {
            font-size: 0.613333rem;
          }
        }
      }
    }
  }
  .texter {
    width: 10rem;
    height: 8.906667rem;
  }
  .images {
    width: 10rem;
    height: 1.173333rem;
    margin-top: -1.333333rem;
  }
}
@keyframes mymove {
  0% {
    transform: scale(1); /*开始为原始大小*/
  }
  25% {
    transform: scale(1.1); /*放大1.1倍*/
  }
  50% {
    transform: scale(1);
  }
  75% {
    transform: scale(1.1);
  }
}
@-webkit-keyframes mymove /*Safari and Chrome*/ {
  0% {
    transform: scale(1); /*开始为原始大小*/
  }
  25% {
    transform: scale(1.1); /*放大1.1倍*/
  }
  50% {
    transform: scale(1);
  }
  75% {
    transform: scale(1.1);
  }
}
</style>
